package kids.movies.hoathinhHDSRC.db;

import java.util.ArrayList;

import android.content.Context;

import com.telpoo.frame.database.BaseDBSupport;
import com.telpoo.frame.object.BaseObject;


public class DbSupport {
public static void initDb(Context context){
		BaseDBSupport.init(TableDb.tables, TableDb.keys, context, TableDb.pathDbName, 2);
	}
	
	public static ArrayList<InfoOj> getCache(String table){
		ArrayList<BaseObject> ojs = BaseDBSupport.getAllOfTable(table);
		return convertOj(ojs);
		
	}
	
	public static ArrayList<InfoOj> getCacheID(String table,String[] id){
		ArrayList<BaseObject> ojs = BaseDBSupport.getAllOfTable(table, id);
		return convertOj(ojs);
		
	}
	public static void saveCache(ArrayList<BaseObject> ojs,String table){
		BaseDBSupport.removeAllInTable(table);
		BaseDBSupport.addToTable(ojs,table);
		
	}
	public static  ArrayList<InfoOj> convertOj(ArrayList<BaseObject> ojs) {
		ArrayList<InfoOj> info = new ArrayList<InfoOj>();

		for (BaseObject oj : ojs) {

			InfoOj oj1 = new InfoOj();
			oj1.setParams(oj.getParams());
			info.add(oj1);

		}

		return info;
	}
}
